package com.go4thx.table.day;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.util.Calendar;

import javax.swing.JLabel;
import javax.swing.JPanel;

import net.miginfocom.swing.MigLayout;

import com.go4thx.util.ChineseCalendar;

public class DayPanel extends JPanel {

	private static final long serialVersionUID = 1L;
	private static final String MS_YAHEI = "Microsoft YaHei";
	
	public DayPanel(ChineseCalendar cc, String today) {
		//panel style
		setLayout(new MigLayout());
		setBackground(Color.WHITE);
		//label
		if (cc != null) {
			
			/**
			 * 班种标识
			 */
			JLabel dutyFlag = new JLabel(cc.getChinese(ChineseCalendar.DUTY));
			dutyFlag.setFont(new Font(MS_YAHEI, Font.PLAIN, 10));
			dutyFlag.setMaximumSize(new Dimension(30, 10));
			dutyFlag.setMinimumSize(new Dimension(30, 10));
			/**
			 * 日期
			 */
			JLabel gregorianDay = new JLabel(String.valueOf(cc.get(Calendar.DATE)));
			gregorianDay.setFont(new Font(MS_YAHEI, Font.BOLD, 20));
			gregorianDay.setMaximumSize(new Dimension(40, 24));
			//今天
			if (cc.toString().equals(today)) {
				setBackground(Color.ORANGE);
			}
			//周末
			if (cc.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || cc.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
				gregorianDay.setForeground(Color.RED);
			}
			
			/**
			 * 农历 & 节气
			 */
			JLabel lunarDay = new JLabel(cc.getChinese(ChineseCalendar.CHINESE_TERM_OR_DATE));
			lunarDay.setFont(new Font(MS_YAHEI, Font.PLAIN, 10));
			
			//add component
			add(dutyFlag, "cell 0 2 1 1");
			add(gregorianDay, "cell 2 0 2 2");
			add(lunarDay, "cell 2 2 1 1");
		}
	}
}
